#include "BasicTutorial2.h"

//-------------------------------------------------------------------------------------
BasicTutorial2::BasicTutorial2(void)
{
}
//-------------------------------------------------------------------------------------
BasicTutorial2::~BasicTutorial2(void)
{
}

//-------------------------------------------------------------------------------------
void BasicTutorial2::createScene(void)
{
	//Set ambient light to complete darkness
	mSceneMgr->setAmbientLight(Ogre::ColourValue(0, 0, 0));
	//Set shadow mode
    mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);

	//Add an entity to cast a shadow
	Ogre::Entity* entNinja = mSceneMgr->createEntity("Ninja", "ninja.mesh");
    entNinja->setCastShadows(true);
	//Attach the entity to a scenenode
    mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entNinja);

	//Create a plane for the entity to cast its shadows on
	Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0);

	//Create a mesh for the plane instead of loading one like ninja.mesh
	Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500, 1500, 20, 20, true, 1, 5, 5, Ogre::Vector3::UNIT_Z);
	
	//Create an entity with the mesh made above
	Ogre::Entity* entGround = mSceneMgr->createEntity("GroundEntity", "ground");
	//Attach the entity to a scenenode
    mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entGround);
	//Add a texture to the ground entity
	entGround->setMaterialName("Examples/Rockwall");
    entGround->setCastShadows(false);
	
	//Create a pointlight and set its position
	Ogre::Light* pointLight = mSceneMgr->createLight("pointLight");
    pointLight->setType(Ogre::Light::LT_POINT);
    pointLight->setPosition(Ogre::Vector3(0, 150, 250));
	//Set diffusion and specular
	pointLight->setDiffuseColour(1.0, 0.0, 0.0);
    pointLight->setSpecularColour(1.0, 0.0, 0.0);

	//Create a directionallight and set its position
	Ogre::Light* directionalLight = mSceneMgr->createLight("directionalLight");
    directionalLight->setType(Ogre::Light::LT_DIRECTIONAL);
	//Set diffusion and specular
    directionalLight->setDiffuseColour(Ogre::ColourValue(.25, .25, 0));
    directionalLight->setSpecularColour(Ogre::ColourValue(.25, .25, 0));
	directionalLight->setDirection(Ogre::Vector3( 0, -1, 1 ));

	Ogre::Light* spotLight = mSceneMgr->createLight("spotLight");
    spotLight->setType(Ogre::Light::LT_SPOTLIGHT);
    spotLight->setDiffuseColour(0, 0, 1.0);
    spotLight->setSpecularColour(0, 0, 1.0);
	spotLight->setDirection(-1, -1, 0);
    spotLight->setPosition(Ogre::Vector3(300, 300, 0));
	spotLight->setSpotlightRange(Ogre::Degree(35), Ogre::Degree(50));
}


//-------------------------------------------------------------------------------------
void BasicTutorial2::createCamera(void)
{
	// create the camera
    mCamera = mSceneMgr->createCamera("PlayerCam");
	// set its position, direction  
    mCamera->setPosition(Ogre::Vector3(0,10,500));
    mCamera->lookAt(Ogre::Vector3(0,0,0));
	// set the near clip distance
    mCamera->setNearClipDistance(5);

	// create a default camera controller
	mCameraMan = new OgreBites::SdkCameraMan(mCamera); 
}
//-------------------------------------------------------------------------------------
void BasicTutorial2::createViewports(void)
{
	// Create one viewport, entire window
	Ogre::Viewport* vp = mWindow->addViewport(mCamera);
	//set background colour
	vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
	// Alter the camera aspect ratio to match the viewport
    mCamera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight())); //Eigenlijk alleen nodig wanneer niet fullscreen
}
